package com.supor.aiot.common.app.api;

import com.android.baseconfig.base.BaseApiResult;
import com.android.baseconfig.base.DataApiResult;
import com.supor.aiot.common.app.Constants;
import com.supor.aiot.common.entity.DeviceTree;
import com.supor.aiot.common.entity.ProductType;

import java.util.List;
import java.util.Map;

import io.reactivex.rxjava3.core.Observable;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: DeviceService <br>
 * 作者: lei <br>
 * 日期: 2021/9/20 <br>
 */
public interface DeviceService {

    /**
     * 获取设备列表树(/bossTAppliancesModel/user/page?limit=1000)
     *
     * @param limit 1000
     * @return Observable<BaseApiResult<DataApiResult<List<ProductType>>>>
     */
    @GET(Constants.OSS_API + "bossTAppliancesModel/user/page")
    Observable<BaseApiResult<DataApiResult<List<ProductType>>>> getAllDevice(@Query("limit") int limit);

    /**
     * 获取设备列表树(/bossTAppliancesModel/json/page?limit=1000)
     *
     * @param limit 1000
     * @return Observable<BaseApiResult<DataApiResult<List<ProductType>>>>
     */
    // @FormUrlEncoded
    @GET(Constants.OSS_API + "bossTAppliancesModel/json/page")
    Observable<BaseApiResult<DataApiResult<List<ProductType>>>> getAllProduct(@Query("limit") int limit);

    /**
     * 获取绑定的设备列表(device/list)
     *
     * @return Observable<BaseApiResult<DeviceTree>>
     */
    // @FormUrlEncoded
    @GET(Constants.OSS_API + "device/list")
    Observable<BaseApiResult<DeviceTree>> getBindDevice();

    /**
     * 设备绑定
     *
     * @param map
     *          mac         设备mac           设备侧读取到的mac
     *          thirdType   第三方类型         固定值Gizwits
     * @return Observable<BaseApiResult<String>>
     */
    // @FormUrlEncoded
    @POST(Constants.OSS_API + "device/bind")
    Observable<BaseApiResult<String>> bind(@Body Map<String, String> map);

    /**
     * 设备解绑
     *
     * @param map
     *          mac	    设备mac           设备侧读取到的mac
     *          did	    设备唯一标识       设备侧读取到的did
     * @return Observable<BaseApiResult<String>>
     */
    // @FormUrlEncoded
    @Headers({
            "X-Supor-Signature-Debug: true",
            "sign-test: true"
    })
    @POST(Constants.OSS_API + "device/unbind")
    Observable<BaseApiResult<String>> unbind(@Body Map<String, String> map);

    /**
     * 查询设备在线离线状态，后台对应机智云snoti通知更新Redis在线状态
     *
     * @param mac 设备MAC地址
     * @return Observable<BaseApiResult<String>>
     */
    @GET(Constants.OSS_API + "device/status")
    Observable<BaseApiResult<String>> queryStatus(@Query("mac") String mac);

    /**
     * 查询设备在线离线状态，后台对应机智云企业API查询在线状态
     *
     * @param mac 设备MAC地址
     * @return Observable<BaseApiResult<String>>
     */
    @GET(Constants.OSS_API + "device/status/detail")
    Observable<BaseApiResult<String>> apiQueryStatus(@Query("mac") String mac);

    /**
     * 上报绑定结果
     *
     * @param requestBody requestBody
     * @return Observable<BaseApiResult<String>>
     */
    // @FormUrlEncoded
    @Headers({
            "X-Supor-Signature-Debug: true",
            "sign-test: true"
    })
    @POST(Constants.OSS_API + "bossTUserDeviceWeb")
    Observable<BaseApiResult<String>> pushBindResult(@Body RequestBody requestBody);


    /**
     * 更新MAC
     *
     * @param oldMac 原来的MAC
     * @param newMac 新的MAC
     * @param thirdType 平台必需是Supor
     *
     * @return Observable<BaseApiResult<Boolean>>
     */
    @POST(Constants.OSS_API + "device/updateMac")
    Observable<BaseApiResult<Boolean>> updateMac(@Query("newMac") String newMac,
                                                 @Query("oldMac") String oldMac,
                                                 @Query("thirdType") String thirdType);

}
